﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 **/

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Peter.Common.MainMenu;
using Peter.Common.Utilities;
using Peter.Ftp.Logic;
using Peter.Ftp.Tests.DataAccess;

namespace Peter.Ftp.Tests.Logic
{
   /// <summary>
   /// Test cases for the FtpConnectionMenuItem class.
   /// </summary>
   [TestClass]
   public class FtpConnectionMenuItemTests
   {
      /// <summary>
      /// Verifies that an exception is thrown if the connection data is null.
      /// </summary>
      [TestMethod]
      [ExpectedException (typeof (ArgumentNullException))]
      public void TestNullConnectionData ()
      {
         new FtpConnectionMenuItem (null, null);
      }

      /// <summary>
      /// Tests the FtpConnectionMenuItem constructor.
      /// </summary>
      [TestMethod]
      public void TestConstructor ()
      {
         var data = FtpConnectionTests.ConnectionData;
         var menuItem = new FtpConnectionMenuItem (data, null);
         Assert.AreEqual (menuItem.Icon, MainMenuIcon.Ftpaccounts, "Unrecognized icon for FtpConnectionMenuItem.");
         Assert.AreEqual (data.Name, menuItem.Title, "FtpConnectionMenuItem title is incorrect.");
         Assert.AreEqual (data.UserName + "@" + data.Server, menuItem.ToolTip,
            "FtpConnectionMenuItem tool tip is incorrect.");
         Assert.AreEqual (data, menuItem.CommandParameter,
            "FtpConnectionMenuItem command parameter should be the connection data.");
      }

      /// <summary>
      /// Tests the FtpConnectionMenuItem property changes.
      /// </summary>
      [TestMethod]
      public void TestPropertyChanges ()
      {
         var data = FtpConnectionTests.ConnectionData.CloneProperties ();
         var menuItem = new FtpConnectionMenuItem (data, null);
         data.Name = "NewTestName";
         Assert.AreEqual ("NewTestName", menuItem.Title, "FtpConnectionMenuItem title was not updated.");
         data.UserName = "NewUserName";
         Assert.AreEqual ("NewUserName@" + data.Server, menuItem.ToolTip, "FtpConnectionMenuItem tooltip was not updated.");
         data.Server = "NewServer";
         Assert.AreEqual ("NewUserName@NewServer", menuItem.ToolTip, "FtpConnectionMenuItem tooltip was not updated.");
      }
   }
}
